from tornado.web import RequestHandler
from wechat import wechat
from auth import wechat_required


class ValidateHandler(RequestHandler):  # check server
    def get(self):
        signature = self.get_query_argument('signature')
        timestamp = self.get_query_argument('timestamp')
        nonce = self.get_query_argument('nonce')
        echostr = self.get_query_argument('echostr')
        validate = wechat.check_signature(signature=signature, timestamp=timestamp, nonce=nonce)
        print('validate: %s' % validate)
        if validate:
            self.write(echostr)


class RegisterHandler(RequestHandler):
    def get(self):
        self.write('welcome to join us')


class AdminHandler(RequestHandler):
    def get(self):
        self.write('nothing to do for admin...')


class WebAuthHandler(RequestHandler):
    @wechat_required('oJ6-vwWMDVB-pB7kSYHLuZmppv8A')
    def get(self):
        self.write('You have granted us access to your openid %s' % self.openid)



